<?php
namespace app\api\controller\v1;
use app\api\controller\Common;

class Jifen extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("Jifen");
	}
	public function day_sign_add(){
		$this->postData['userid'] = $this->uinfo['id'];
		// $result = $this->validate($this->postData, 'Jifen.check_task');
		// if ($result !== true) {
		// 	return $this->app_error($result);
		// }
		$id = $this->modelDb->save_datas($this->postData);
		if ($id) {
			return $this->app_success();
		}else{
			return $this->app_error($this->modelDb->getError());
		}
	}
	public function convert_add(){
		$info = model("Convert")->get_data(['item_id'=>$this->postData['contentid']]);
		if ($this->uinfo['jifen'] < $info['price']) {
			return $this->app_error('积分不足');
		}
	    $this->postData['typeid'] = 1;
	    $this->postData['userid'] = $this->uinfo['id'];
	    $this->postData['nums'] = -$info['price'];
	    $this->postData['taskid'] = 0;
      	$id = $this->modelDb->save_datas($this->postData);
		if(!$id){
			return $this->app_error($this->modelDb->getError());
		}
        // model('Member')->where('id',$this->uinfo['id'])->setDec('jifen',$info['price']);
		return $this->app_success();
	}
}